<?php
/**
 * Created by PhpStorm.
 * User: Wang YuLong
 * Date: 2018/11/14
 * Time: 15:02
 */
namespace app\index\model;

use think\model;

class Details extends Model
{
    public function index($id)
    {
        $data = $this->where('issueid',$id)->select();
        $info = [];
        foreach($data as $key)
        {
            $info[] = $key->toArray();
        }
        return $info;
    }

    public function adddo($id,$image)
    {
        foreach($image as $image)
        {
            $details = new Details();
            $sort= $details->where('issueid',$id)->max('sort');
            $time=date('Ymd',time());
            $filename=time().$id.$sort++;
            if(!file_exists(ROOT_PATH . 'public' . DS .'static'. DS .'img_issue'))
            {
                //创建文件
                mkdir(ROOT_PATH . 'public' . DS .'static'. DS .'img_issue');
            }
            $info=$image->move(ROOT_PATH . 'public' . DS .'static'. DS .'img_issue'.DS.$time,$filename);
            $details->url          =  $time.DS.$info->getFileName();
            $details->issueid   =  $id;
            $details->sort        =  $sort;
            $details->allowField(true)->save();
        }
        return 1;
    }
}